package com.znufe.exam.controller.h5;

import com.github.pagehelper.PageInfo;
import com.znufe.exam.base.BaseApiController;
import com.znufe.exam.base.RestResponse;
import com.znufe.exam.configuration.config.service.TokenService;
import com.znufe.exam.domain.ExamPaperRule;
import com.znufe.exam.service.ExamPaperRuleService;
import com.znufe.exam.utility.DateTimeUtil;
import com.znufe.exam.utility.PageInfoHelper;
import com.znufe.exam.viewmodel.admin.exam.ExamRuleRequestVM;
import com.znufe.exam.viewmodel.admin.exam.ExamRuleResponseVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @Description: 规则显示接口层
 * @Author:      yang shuo
 * @CreateDate:  ExamPrincipleRecord
 * @Version:     V1.0
 */

@Api(description = "试卷规则", value = "试卷规则")
@RestController("H5ExamPaperRuleController")
@RequestMapping(value = "/api/h5/exam/rule")
@AllArgsConstructor
public class ExamPaperRuleController extends BaseApiController {

    private final ExamPaperRuleService examPaperPrincipleService;

    @Autowired
    private TokenService tokenService;

    @PreAuthorize("@ss.hasPermi('exam:paper:list')")
    @RequestMapping(value = "/page", method = RequestMethod.POST, produces = "application/json")
    @ApiOperation(value = "试卷信息的页面查询接口（无参数查找/按试卷类别查找/按试卷名称查找）",
            notes = "查询试卷信息[t_exam_paper]，作者：yang shuo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "试卷id，测试：1", required = true, dataType = "Integer", paramType = "body"),
            @ApiImplicitParam(name = "subjectId", value = "学科id，测试：1", required = true, dataType = "Integer", paramType = "body"),
            @ApiImplicitParam(name = "level", value = "等级，测试：12", required = true, dataType = "Integer", paramType = "body"),
            @ApiImplicitParam(name = "name", value = "试卷名称，测试：测试", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "taskExamId", value = "测试：0", required = true, dataType = "Integer", paramType = "body"),
            @ApiImplicitParam(name = "paperType", value = "测试：0", required = true, dataType = "Integer", paramType = "body"),
    })
    public RestResponse<PageInfo<ExamRuleResponseVM>> pageList(@RequestBody ExamRuleRequestVM model) {
        model = ExamRuleRequestVM.wipeBlank(model);
        PageInfo<ExamPaperRule> pageInfo = examPaperPrincipleService.page(model);
        PageInfo<ExamRuleResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> {
            //借用ExamResponse的返回数据结构
            ExamRuleResponseVM vm = modelMapper.map(e, ExamRuleResponseVM.class);
            vm.setCreateTime(DateTimeUtil.dateFormat((e.getCreateTime())));
            return vm;
        });
        return RestResponse.ok(page);
    }

}
